package com.shupian.controller;

import com.shupian.annotation.SystemLog;
import com.shupian.domain.ResponseResult;
import com.shupian.domain.dto.RegisterUserDTO;
import com.shupian.domain.dto.UpdataUserInfoDTO;
import com.shupian.domain.entity.User;
import com.shupian.service.UserService;
import com.shupian.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "用户相关接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 查询用户信息
     * @return
     */
    @ApiOperation(value = "个人信息查询接口",notes ="需要token请求头" )
    @GetMapping("/userInfo")
    public ResponseResult userInfo(){

        return userService.userInfo();
    }

    /**
     * 更新用户信息
     * @param userInfoDTO
     * @return
     */
    @ApiOperation(value = "个人信息更新接口", notes = "需要token请求头")
    @PutMapping("/userInfo")
    @SystemLog(businessName = "更新用户信息")
    public ResponseResult updataUserInfo(@RequestBody @Valid UpdataUserInfoDTO userInfoDTO){
        User user = BeanCopyUtils.copyBean(userInfoDTO, User.class);
        return userService.updateUserInfo(user);
    }

    /**
     * 注册用户
     * @param registerUserDTO
     * @return
     */
    @ApiOperation(value = "用户注册", notes = "不需要token请求头")
    @PostMapping("/register")
    public ResponseResult register(@RequestBody @Valid RegisterUserDTO registerUserDTO){
        User user = BeanCopyUtils.copyBean(registerUserDTO, User.class);
        return userService.register(user);
    }

}
